import Qs from "qs";
import Vue from "vue";
import App from "./App.vue";
import "./home.scss";
import { http, _http } from "./http";
import "./plugins/element.js";
import router from "./router";
import "./style.scss";
import util from "./utils";
import HappyScroll from "vue-happy-scroll";
// 引入css
import "vue-happy-scroll/docs/happy-scroll.css";
// import $ from 'jquery'
// import GeminiScrollbar from 'vue-gemini-scrollbar'
Vue.config.productionTip = false;

Vue.prototype.$http = http;
Vue.prototype.$_http = http;
Vue.prototype.$util = util;
Vue.prototype.Qs = Qs;
Vue.prototype.assetsURL = `http://www.huitengit.com/jdpth/HJResourse/`;
Vue.prototype.clearObj = (obj, skipAtt) => {
  for (const key in obj) {
    if (obj[key] && (skipAtt ? skipAtt.indexOf(key) == -1 : true)) {
      obj[key] = "";
    }
  }
};

Vue.prototype.appandFile = (file, cb, img) => {
  function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, img.width, img.height);
    var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
    var dataURL = canvas.toDataURL("image/" + ext);

    return dataURL;
  }
  var image = new Image();
  image.setAttribute("crossOrigin", "Anonymous");
  image.src = img;
  image.onload = function() {
    var base64 = getBase64Image(image);
    //转换base64到file
    file = btof(base64, "test");
    cb(file);
  };

  function btof(data, fileName) {
    const dataArr = data.split(",");
    const byteString = atob(dataArr[1]);
    // ['image/jpeg', 'image/png', 'image/gif', 'image/png']
    const options = {
      type: "image/jpeg",
      endings: "native",
    };
    const u8Arr = new Uint8Array(byteString.length);
    for (let i = 0; i < byteString.length; i++) {
      u8Arr[i] = byteString.charCodeAt(i);
    }
    return new File([u8Arr], fileName + ".jpg", options);
  }
};

Vue.config.silent = true;

Vue.use(HappyScroll);
Vue.use(router);

new Vue({
  router,
  render: (h) => h(App),
}).$mount("#app");
